﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace JM.JCY.SharePointComponent.News.LeftMenuNews
{
    public partial class LeftMenuNewsUserControl : UserControl
    {
        public string _category
        {
            set { ViewState["_category"] = value; }
            get { return (string)ViewState["_category"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string sourceDirectory = this.Parent.AppRelativeTemplateSourceDirectory;    //Example:   ~/_CONTROLTEMPLATES/NCS.OCP.SharePointComponent.Broadcast/CreateBroadcastsRole/
            string webPartName = sourceDirectory.Substring(sourceDirectory.TrimEnd('/').LastIndexOf('/') + 1).TrimEnd('/');
            if (webPartName == "CreateNews" || webPartName == "EditNews" ||
                webPartName == "ManageNews" || webPartName == "SearchNews" || webPartName == "ViewNewsDetail")
            {
                this.lkbManageNews.CssClass = "leftmenuSelected";
            }

            if (!IsPostBack)
            {
                if (Request.QueryString["category"] != null)
                {
                    _category = Request.QueryString["category"].ToString();
                    this.hfLeftCategory.Value = _category;
                }

                if (_category == "News")
                {
                    this.imgIcon.ImageUrl = "/_layouts/JM.JCY.Resource/images/新闻小.png";
                    this.lblNewsCategory.Text = "新闻中心";
                    this.lkbManageNews.Text = "管理新闻";
                }
                else
                {
                    this.imgIcon.ImageUrl = "/_layouts/JM.JCY.Resource/images/领导讲话小.png";
                    this.lblNewsCategory.Text = "领导讲话";
                    this.lkbManageNews.Text = "管理领导讲话";
                }
            }
        }
    }
}
